
-- -- -- -- -- -- -- --
-- -- Projectile -- -- -- --
-- -- -- -- -- -- -- --

Projectile = Gameelement:new{
  owner = "default",
  cost = 0,
  damage = 0,
  movementSpeed = 1,
  width = 10,
  height = 10,
  direction = 1,
  image = { 'resources/onearrow.png'},
	target = gameelements,
	stateList={ 
		 flying = {
			name = "flying",
			actions = {
				function(t)
					t:fly()
				end,
					function (t)
									target_ = physic.gameelementCollision(t)
									if  target_ then					
										t:dealDamage(target_, t.damage, t.owner)
										t:changeState(t.stateList.destroy)
									end
					end,
			}
		},
		delay = {
				name = "delay",
				actions = {		
					function (t)
						i = i + 1
						if i > 3 
						then
							t:changeState(t.stateList.flying)
						end
					end
				}
			}
}
}

function Projectile:statusCheck()
		if	not physic.mapBorderCollision(self) then 
				self:changeState(self.stateList.destroy)
		end
end

function Projectile:fly()
	if self.direction == 1 then 
		self.velocity = {0,-self.movementSpeed}--north
	elseif self.direction == 2 then 
		self.velocity = {self.movementSpeed,0}--east
	elseif self.direction == 3 then 
		self.velocity = {0,self.movementSpeed}--south
	elseif self.direction == 4 then
	 	self.velocity = {-self.movementSpeed,0}--west
	elseif self.direction == 5 then 
		self.velocity = {self.movementSpeed,-self.movementSpeed}--northeast
	elseif self.direction == 6 then 
		self.velocity = {self.movementSpeed,self.movementSpeed}--southeast
	elseif self.direction == 7 then 
		self.velocity = {-self.movementSpeed,self.movementSpeed}--southwest
	elseif self.direction == 8 then 
		self.velocity = {-self.movementSpeed,-self.movementSpeed}--northwest
	else 
			self.velocity = {0,0}
	end
end
Projectile.currentState = Projectile.stateList.flying
------------------------------------------------

Arrow = Projectile:new{
  cost = 1,
  damage = 13,
  movementSpeed = 2,
  width = 2,
  height = 2
}
Arrow.image = {
	'resources/onearrow.png'
}

 -- -- -- -- -- -- --
-- -- Fireball -- -- --
-- -- -- -- -- -- -- --
Fireball = Projectile:new{
	name = "fireball",
	movementSpeed = 10,
	cost = 10,
	damage = 15,
	width = 20,
	height = 20,
	sprite = "resources/onefireball.png"	
}

-- -- -- -- -- -- -- --
-- -- Lightning -- -- --
-- -- -- -- -- -- -- --
Lightning = Projectile:new{ 
	movementSpeed = 1.5,
	cost = 10,
	damage = 15,
	width = 20,
	height = 20,
	image = {
		"resources/lightning.png"	
	}
}